﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace project.UI.sdudent
{
    public partial class LookBook : BookPage
    {
        public LookBook()
        {
            InitializeComponent();
            this.Size = new System.Drawing.Size(1271, 631);
            this.uiDataGridView1.Size = new System.Drawing.Size(1201, 561);
        }

        private void uiButton2_Click(object sender, EventArgs e)
        {
            //借阅
 int selectCount = uiDataGridView1.SelectedRows.Count;
            if (selectCount != 0)
            {
                if (MessageBox.Show("你确认要借阅当前选中行的书吗？此操作不可回退", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    int id = int.Parse(uiDataGridView1.SelectedRows[0].Cells[0].Value.ToString());


                    int result = (int)SqlHelper.rent_books(LoginHelper.whoami,id.ToString());
                    if (result != 0)
                    {
                        MessageBox.Show("借阅成功", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        QueryAllBook();
                    }
                    else
                    {
                        MessageBox.Show("借阅失败", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
            else
            {
                MessageBox.Show("请选择正确的数据", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
    }
}
